/*
 * Copyright (C) 2016
 *
 * Brick Yang <printfxxx@163.com>
 *
 * This program is free software. You can redistribute it and/or
 * modify it as you like.
 */

/**
 * @file	bman.h
 * @brief	Header file for bman driver
 */

#ifndef _BMAN_H_
#define _BMAN_H_

#include <linux/types.h>
#include <linux/device.h>

/* bman software portal descriptor structure */
struct bman_swp_desc {
	void *cena_bar;
	void *cinh_bar;
	size_t cena_size;
	size_t cinh_size;
	unsigned long flags;
	#define SWP_F_RCR_VB	0x01
};

/* portal data structure */
struct bman_swp {
	const struct bman_swp_desc *desc;
	void __iomem *addr_cena;
	void __iomem *addr_cinh;

	/* CR */
	struct {
		u8 valid_bit;
	} cr;

	/* RCR */
	struct {
		u8 pi, ci, fi;
		u8 pi_ci_mask;
		u8 valid_bit;
	} rcr;
};

static inline void bman_swp_cmd_zero(void __iomem *p)
{
	u32 *w = p;

	w[0] = 0;
	w[1] = 0;
	w[2] = 0;
	w[3] = 0;
	w[4] = 0;
	w[5] = 0;
	w[6] = 0;
	w[7] = 0;
	w[8] = 0;
	w[9] = 0;
	w[10] = 0;
	w[11] = 0;
	w[12] = 0;
	w[13] = 0;
	w[14] = 0;
	w[15] = 0;
}

struct bman_swp *bman_swp_init(const struct bman_swp_desc *d);
void bman_swp_finish(struct bman_swp *s);
void __iomem *bman_swp_cr_next(struct bman_swp *s, u8 *cmd_verb);
const void __iomem *bman_swp_rr_next(struct bman_swp *s, u8 cmd_verb);
void __iomem *bman_swp_rcr_next(struct bman_swp *s, u8 *cmd_verb);
void bman_swp_cr_submit(struct bman_swp *s, void __iomem *p, u8 cmd_verb);
int bman_swp_rcr_submit(struct bman_swp *s, void __iomem *p, u8 cmd_verb, bool flush);

#endif	/* _BMAN_H_ */
